﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TPAMainReportTools
{
    public partial class frmLogin : Form
    {
        public bool bLoginSuccess = false;
        public UserInfo ui;

        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            txtUserName.Focus();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Equals(string.Empty))
            {
                GeneralTools.ShowInfoMsg("用户名称不能为空！");
                txtUserName.Focus();
                return;
            }
            UserInfo tmpui = new UserInfo(txtUserName.Text, txtPassword.Text);
            if (tmpui.LoginSuccess)
            {
                bLoginSuccess = true;
                ui = tmpui;
                this.Close();
            }
            else
            {
                GeneralTools.ShowErrorMsg("登录失败：" + tmpui.LoginErrMsg);
                return;
            }
        }

        public static frmLogin Show()
        {
            frmLogin newFrmLogin = new frmLogin();
            newFrmLogin.ShowDialog();
            return newFrmLogin;
        }

        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                btnLogin_Click(this, new EventArgs());
            }
        }

    }
}